var daum_adam_manager = {
    initFlag: false,
    reqUrl: "http://m.adtc.daum.net/mobilead?output=js",
    param: {},
    info: {
        txSize: 13,
        gap: 10,
        lSize: 38,
        rSize: 27,
        lRadius: 4,
        rRadius: 2,
        content: 215,
        bannerid: "daum_adam_banner",
        banner: null,
        position: "MIDDLE",
        width: 320,
        height: 48,
        bgextend: true,
        nwin: true
    },
    data: null,
    clked: false,
    gv: {
        ua: navigator.userAgent.toLowerCase(),
        isIphone: false,
        isWebkit: false,
        isAndroid: false,
    },
    setAreaStyle: function (B) {
        for (var A = 1; A < arguments.length; A += 2) {
            B.style[arguments[A]] = arguments[A + 1]
        }
    },
    getParam: function () {
        var D = "";
        for (var B in this.param) {
            if (typeof B !== "undefined") {
                D += "&" + B + "=" + this.param[B]
            }
        }
        var A = Math.random().toString();
        var C = A.substring(2, A.length);
        D += "&ordval=" + C;
        return D
    },
    loadStyle: function () {
        var A;
        var B = document.createElement("link");
        B.setAttribute("rel", "stylesheet");
        B.setAttribute("type", "text/css");
        B.setAttribute("href", "data:text/css;base64,I2RhdW1fYWRhbV9iYW5uZXIgKiB7bWFyZ2luOjA7cGFkZGluZzowO30KI2RhdW1fYWRhbV9iYW5uZXIgYm9keSB7YmFja2dyb3VuZC1jb2xvcjojZmZmO30KI2RhdW1fYWRhbV9iYW5uZXIgYSB7dGV4dC1kZWNvcmF0aW9uOm5vbmV9CiNkYXVtX2FkYW1fYmFubmVyIC5hZCB7d2lkdGg6MTAwJTtoZWlnaHQ6MTAwJTttYXJnaW46MCBhdXRvO3Bvc2l0aW9uOnJlbGF0aXZlO2Rpc3BsYXk6YmxvY2t9CiNkYXVtX2FkYW1fYmFubmVyX2ljb24ge3Bvc2l0aW9uOmFic29sdXRlO2JvcmRlcjowfQojZGF1bV9hZGFtX2Jhbm5lcl9pY29uRG4ge3Bvc2l0aW9uOmFic29sdXRlO2JvcmRlcjowfQojZGF1bV9hZGFtX2Jhbm5lcl9pY29uIHtib3gtc2hhZG93OjBweCAxcHggM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WF0OnJlcGVhdC14O2JhY2tncm91bmQtcG9zaXRpb246dG9wIGNlbnRlcn0=");
        if (document.getElementsByTagName("head").length) {
            document.getElementsByTagName("head")[0].appendChild(B)
        } else {
            document.body.appendChild(B)
        }
    },
    defaultHTML: function (A) {
        if (A.length == 0) {
            return false
        }
        daum_adam_manager.data = A[0];
        daum_adam_manager.setBgColor();
        switch (daum_adam_manager.data.type) {
        case "T":
            daum_adam_manager.createAd_typeT();
            daum_adam_manager.setTxColor();
            break;
        case "B":
            daum_adam_manager.createAd_typeB();
            break;
        default:
            break
        }
    },
    createAd_typeT: function () {
        var A = this.info.banner;
        var B = "";
        B += '<a onclick="javascript:daum_adam_manager.traceHandler();" class="ad">';
        B += '<div id="' + this.info.bannerid + '_desc" style="width:' + this.info.width + "px;height:" + this.info.height + "px;";
        if (!this.info.bgextend) {
            if (this.info.bgcolor && this.info.bgcolor != undefined && this.info.bgcolor.length != 0) {
                B += "background-color:" + this.info.bgcolor
            } else {
                if (this.info.bgimg && this.info.bgimg != undefined && this.info.bgimg.length != 0) {
                    B += "background-image:url(" + this.info.bgimg + ")"
                } else {
                    if (this.data.bgimg && this.data.bgimg != undefined && this.data.bgimg.length != 0) {
                        B += "background-image:url(" + this.data.bgimg + ")"
                    } else {
                        if (this.data.bgcolor && this.data.bgcolor != undefined && this.data.bgcolor.length != 0) {
                            B += "background-color:" + this.info.bgcolor
                        }
                    }
                }
            }
        }
        B += '">';
        B += '<img id="' + this.info.bannerid + '_icon" width="' + this.info.lSize + '" height="' + this.info.lSize + '" src="' + this.data.image + '" style="left:' + this.info.gap + "px;top:" + parseInt(this.info.gap * 0.5 - 1) + "px;border-radius:" + this.info.lRadius + "px;-moz-border-radius:" + this.info.lRadius + 'px"/>';
        B += '<p id="' + this.info.bannerid + '_txt" style="width:' + this.info.content + 'px">' + this.data.text + "</p>";
        B += '<img id="' + this.info.bannerid + '_iconDn" width="' + this.info.rSize + '" height="' + this.info.rSize + '" src="' + this.data.ctypeimg + '" style="top:' + this.info.gap + "px;right:" + this.info.gap + "px;border-radius:" + this.info.rRadius + "px;-moz-border-radius:" + this.info.rRadius + 'px"/></div></a>';
        A.innerHTML = B;
        var D = document.getElementById(this.info.bannerid + "_txt");
        this.setAreaStyle(D, "fontSize", this.info.txSize + "px", "marginLeft", this.info.gap * 2 + this.info.lSize + "px");
        var C = parseInt((this.info.height - D.offsetHeight) / 2);
        if (this.gv.isIphone) {
            C--
        }
        if (this.gv.isAndroid) {
            C++
        }
        this.setAreaStyle(D, "paddingTop", ((C > 0) ? C : 0) + "px")
    },
    createAd_typeB: function () {
        var A = this.info.banner;
        var B = "";
        B = '<a onclick="javascript:daum_adam_manager.traceHandler();" class="ad b" ><img id="' + this.info.bannerid + '_imgBanner" src="' + this.data.image + '" style="width:' + this.info.width + "px;height:" + this.info.height + 'px"/></a>';
        A.innerHTML = B
    },
    setBgColor: function () {
        var A = this.info.banner;
        if (!(this.info.bgextend && A)) {
            return false
        }
        if (this.info.bgcolor && this.info.bgcolor != undefined && this.info.bgcolor.length != 0) {
            A.style.backgroundColor = this.info.bgcolor
        } else {
            if (this.info.bgimg && this.info.bgimg != undefined && this.info.bgimg.length != 0) {
                A.style.backgroundImage = "url(" + this.info.bgimg + ")"
            } else {
                if (this.data.bgimg && this.data.bgimg != undefined && this.data.bgimg.length != 0) {
                    A.style.backgroundImage = "url(" + this.data.bgimg + ")"
                } else {
                    if (this.data.bgcolor && this.data.bgcolor != undefined && this.data.bgcolor.length != 0) {
                        A.style.backgroundColor = this.data.bgcolor
                    }
                }
            }
        }
    },
    setTxColor: function () {
        var A = document.getElementById(this.info.bannerid + "_txt");
        if (!(this.info.bgextend && A)) {
            return false
        }
        if (this.info.txcolor && this.info.txcolor != undefined && this.info.txcolor.length != 0) {
            A.style.color = this.info.txcolor
        } else {
            if (this.data.txcolor && this.data.txcolor != undefined && this.data.txcolor.length != 0) {
                A.style.color = this.data.txcolor
            }
        }
    },
    setMagnification: function (A) {
        this.info.txSize = parseInt(this.info.txSize * A);
        this.info.gap = parseInt(this.info.gap * A);
        this.info.lSize = parseInt(this.info.lSize * A);
        this.info.rSize = parseInt(this.info.rSize * A);
        this.info.lRadius = parseInt(this.info.lRadius * A);
        this.info.rRadius = parseInt(this.info.rRadius * A);
        this.info.content = parseInt(this.info.content * A)
    },
    goUrl: function (A) {
        if (this.info.nwin) {
            window.open(A, "_blank", "fullscreen,scrollbars")
        } else {
            document.location = A
        }
    },
    traceHandler: function () {
        try {
            if (this.data.turl !== "" && this.data.turl.length !== 0) {
                var C = this.data.curl;
                if (this.clked == false) {
                    this.clked = true;
                    var A = new Image();
                    A.width = 0;
                    A.height = 0;
                    A.src = this.data.turl;
                    if (A.addEventListener) {
                        A.addEventListener("load", this.goUrl(C))
                    } else {
                        A.attachEvent("onload", this.goUrl(C))
                    }
                    document.body.appendChild(A)
                } else {
                    this.goUrl(C)
                }
            }
        } catch (B) {}
        return true
    },
    includeJS: function (B) {
        var A = document.createElement("script");
        A.type = "text/javascript";
        A.src = B;
        if (document.getElementsByTagName("head").length) {
            document.getElementsByTagName("head")[0].appendChild(A)
        } else {
            document.body.appendChild(A)
        }
    },
    setUA: function () {
        this.gv.isIphone = (this.gv.ua.indexOf("iphone") > -1 && this.gv.ua.indexOf("ipod") === -1);
        this.gv.isWebkit = (this.gv.ua.indexOf("applewebkit") > -1);
        this.gv.isAndroid = (this.gv.ua.indexOf("android") > -1)
    },
    getAdamHeight: function () {
        if (daum_adam_vars.width) {
            if (daum_adam_vars.width < 320) {
                daum_adam_vars.width = 320
            } else {
                if (640 < daum_adam_vars.width) {
                    daum_adam_vars.width = 640
                }
            }
        } else {
            daum_adam_vars.width = 320
        }
        return daum_adam_vars.width * 3 / 20
    },
    contentTop: function () {
        if (document.body.firstChild) {
            document.body.insertBefore(this.info.banner, document.body.firstChild)
        } else {
            document.body.appendChild(this.info.banner)
        }
    },
    contentBtm: function () {
        document.body.appendChild(this.info.banner)
    },
    contentMiddle: function () {
        var A = document.getElementById(this.info.bannerDivId);
        if (A) {
            A.appendChild(this.info.banner)
        } else {
            this.contentBtm()
        }
    },
    init: function () {
        if (this.initFlag) {
            return
        }
        this.initFlag = true;
        this.setUA();
        if (!(this.gv.isIphone || this.gv.isWebkit || this.gv.isAndroid)) {
            return false
        }
        if (window.daum_adam_vars != undefined) {
            this.param.client = daum_adam_vars.client;
            if (daum_adam_vars.reqUrl != undefined) {
                this.reqUrl = daum_adam_vars.reqUrl
            }
            if (daum_adam_vars.test != undefined) {
                this.param.test = daum_adam_vars.test
            }
            if (daum_adam_vars.q != undefined) {
                this.param.q = daum_adam_vars.q
            }
            if (daum_adam_vars.testdomain != undefined) {
                this.param.testdomain = daum_adam_vars.testdomain
            }
            this.info.height = this.getAdamHeight();
            this.info.width = daum_adam_vars.width;
            if (daum_adam_vars.txcolor != undefined) {
                this.info.txcolor = "#" + daum_adam_vars.txcolor
            }
            if (daum_adam_vars.bgcolor != undefined) {
                this.info.bgcolor = "#" + daum_adam_vars.bgcolor
            }
            if (daum_adam_vars.bgextend != undefined) {
                this.info.bgextend = daum_adam_vars.bgextend
            }
            if (daum_adam_vars.position != undefined) {
                this.info.position = daum_adam_vars.position.toUpperCase()
            }
            if (daum_adam_vars.bannerDivId != undefined) {
                this.info.bannerDivId = daum_adam_vars.bannerDivId
            }
            if (daum_adam_vars.newWindow != undefined) {
                this.info.nwin = daum_adam_vars.newWindow
            }
            this.loadStyle();
            this.info.banner = document.createElement("div");
            this.info.banner.setAttribute("id", this.info.bannerid);
            switch (this.info.position) {
            case "TOP":
                this.contentTop();
                break;
            case "BOTTOM":
                this.contentBtm();
                break;
            case "MIDDLE":
                this.contentMiddle();
                break;
            default:
                break
            }
            this.setMagnification(this.info.width / 320);
            window.daum_mobilead_defaultHTML = this.defaultHTML;
            this.includeJS(this.reqUrl + this.getParam())
        }
    }
};
if (window.addEventListener) {
    window.addEventListener("load", function () {
        daum_adam_manager.init.apply(daum_adam_manager)
    }, false)
} else {
    window.attachEvent("onload", function () {
        daum_adam_manager.init.apply(daum_adam_manager)
    })
}
setTimeout(function () {
    if (!daum_adam_manager.initFlag) {
        daum_adam_manager.init()
    }
}, 1000);